<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Configs;
use Illuminate\Http\Request;

class ConfigController extends Controller {

    /**
     * 页面
     * @return view
     */
    public function index(){
        $base = Configs::getConfig('base');
        $integral = Configs::getConfig('integral');
        $service = Configs::getConfig('service');
        $base = json_encode($base);
        $integral = json_encode($integral);
        $service = json_encode($service);
        return view('admin.setting.config',compact('base','integral','service'));
    }

    /**
     * 更新
     * @param Request $request
     * @return bool
     */
    public function update(Request $request)
    {
        try{
            $data = $request->all();
          //  var_dump($data);
            $info = Configs::where('name',$data['type'])->first();
            unset($data['type']);
            $info->update(['setting' => $data]);
            return $this->writeJson(0,null,'更新配置信息成功');
        }catch (\Exception $e){
            return $this->writeJson(1,null,$e->getMessage());
        }
    }

}
